package com.yanqu.road.server.cmd.banquet;

import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.entity.player.UserInfo;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.pb.banquet.BanquetProto;
import com.yanqu.road.pb.player.PlayerProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.manger.banquet.BanquetRelationshipMgr;
import com.yanqu.road.server.manger.player.UserMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameProtocol;
import io.netty.channel.ChannelHandlerContext;

@Cmd(code = GameProtocol.S_CROSS_RELATIONSHIP, desc = "")
public class SyncBanquetRelationshipCmd implements Command {
    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage packet) throws Exception {
        BanquetProto.SyncAddBanquetRelationshipMsg syncMsg = BanquetProto.SyncAddBanquetRelationshipMsg.parseFrom(packet.getBytes());
        for (BanquetProto.AddBanquetRelationshipMsg msg : syncMsg.getDataList()) {
            long myUserId = msg.getMyUserId();
            UserInfo userInfo = UserMgr.getUserInfo(myUserId);
            if (userInfo == null) {
                continue;
            }
            long otherUserId = msg.getOtherUserId();
            PlayerProto.PlayerBaseTempMsg other = msg.getPlayerBaseData();
            UserBaseInfo otherUserBaseInfo = PlayerBasePb.parseBaseUserInfo(other);
            boolean isMyJoin = msg.getIsMyJoin();
            long beginShowTime = msg.getBeginShowTime();
            int banquetType = msg.getBanquetType();
            BanquetRelationshipMgr.addPartyRelationship(myUserId,otherUserId,otherUserBaseInfo,banquetType,beginShowTime,isMyJoin);
        }
    }
}
